<?php
include "../../../lib/list.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<link rel="stylesheet" href="../../../css/insert.css" type="text/css"></link>
<link rel="stylesheet" href="../../../css/list.css" type="text/css"></link>
<script type="text/javascript" src="../../../js/jquery-1.2.6.js"></script>
<script type="text/javascript" src="../../../js/list.js"></script>
<script>
var i;
function setup_category_change(){
    $("select[name='bigcategory[]']").change(update_middlecategory);
    $("select[name='middlecategory[]']").change(update_smallcategory);
}

function update_middlecategory(){
    i = $("select[name='bigcategory[]']").index(this); 
    var b_no = $("select[name='bigcategory[]']").eq(i).attr('value');
    $.get('../../../lib/category.php?b_no='+b_no,show_middlecategory);
    $.get('../../../lib/category.php?m_no=-1',show_smallcategory);
}

function update_smallcategory(){
    i = $("select[name='middlecategory[]']").index(this); 
    var m_no = $("select[name='middlecategory[]']").eq(i).attr('value');
    $.get('../../../lib/category.php?m_no='+m_no,show_smallcategory);
}

function show_middlecategory(res){
    $("select[name='middlecategory[]']").eq(i).html(res);
}

function show_smallcategory(res){
    $("select[name='smallcategory[]']").eq(i).html(res);
}

$(document).ready(setup_category_change);

function show_rot(i){
	var rot = document.getElementsByName("rot[]");
	var show_ul = document.getElementsByName("show_ul[]");
	if(rot[i].checked){
		show_ul[i].style.display = "block";
		}else{
		show_ul[i].style.display = "none";
	}
}

function init(){
	var rot = document.getElementsByName("rot[]");
	var show_ul = document.getElementsByName("show_ul[]");
	for(i=0;i<rot.length;i++){
		if(rot[i].checked){
			show_ul[i].style.display = "block";
			}else{
			show_ul[i].style.display = "none";
		}
		}
}

</script>
</head>
<body onload="javascript:init();">
	<div style="width: 1024px; padding: 10px;">
		<div
			style="border-bottom: 1px solid #e8e8e8; text-align: left; font-size: 12px; margin-bottom: 12px; color: #9a9a9a">:::
			마스터 관리&nbsp;⇒&nbsp;상품 마스터&nbsp;⇒&nbsp;상품 추가하기</div>
		<form name="insert" method="post" action="query.php" enctype="multipart/form-data">
			<input type="hidden" value="" name="before" />
			<input type="hidden" value="insert" name="mode" />
			<div id=register>

			<?php
			$table = "uatp_product";
			if($_POST['mode']=='modify'){
				$no = $_POST['chk_no'];
				for($i=0;$i<count($no);$i++){
					$qry  = "select * from $table where no = $no[$i]";
					$list = DBarray($qry);
					?>

				<!--   /////////////////////	  기존 내용 수정하기	 ///////////////////// -->
				<input type="hidden" value="<?=$no[$i]?>" name="no[]" />
				
			<ul class='line' onload="javascript:test();"></ul>
					<ul>
					<li class='lable'>barcode</li>
						<li class='value'><input type='text' size='20' name='barcode[]' value="<?=$list['barcode']?>" readonly onclick="javascript:chk_barcode('<?=$table?>',this.value);"/>
						</li>
						<li class='explain'>:: 중복 불가능 하며 숫자만 입력 가능합니다.</li>						
					</ul>
					<ul>
					<li class='lable'>상품명</li>
						<li class='value'><input type='text' size='20' name='name[]' value="<?=$list['productname']?>" readonly onclick="javascript:chk_productname('<?=$table?>',this.value);"/>
						</li>
						<li class='explain'>:: 상품명은 중복될 수 없습니다.</li>						
					</ul>
					<ul>
					<li class='lable'>상품명(가나)</li>
						<li class='value'><input type='text' size='20' name='productnamegana[]' value="<?=$list['productnamegana']?>"/>
						</li>					
					</ul>
					<ul>
					<li class='lable'>가격 1</li>
						<li class='value' style="width:170px">
						<input type='text' size='20' name='price1[]' value="<?=$list['price1']?>" onkeyup="number_check(this);" style="text-align:right"/>
						</li>
						<li class='value' style="width:190px">&nbsp;2.
						<input type='text' size='20' name='price2[]' value="<?=$list['price2']?>" onkeyup="number_check(this);" style="text-align:right"/>
						</li>
						<li class='value' style="width:190px">&nbsp;3.
						<input type='text' size='20' name='price3[]' value="<?=$list['price3']?>" onkeyup="number_check(this);" style="text-align:right"/>
						</li>											
					</ul>
					<ul>
					<li class='lable'>구매처</li>
						<li class='value'>
						<select name='buyer[]' style="width:155px; margin-left:2px">
						<option value="">:: 구매처 선택</option>
						<?
						$qry = "SELECT * FROM uatp_buyer";
						$query = DBquery($qry);
						while($buyer = mysql_fetch_array($query)){
							?>
						<option value="<?=$buyer['no']?>"<?if($buyer['no']==$list['buyer']){echo "selected";}?>><?=$buyer['name']?></option>
						<?
						}
						mysql_close();
						?>
						</select>
						</li>					
					</ul>
					<ul>
					<li class='lable'>구매가격</li>
						<li class='value'>
						<input type='text' size='20' name='buyingprice[]' value="<?=$list['buyingprice']?>" onkeyup="number_check(this);" style="text-align:right"/>
						</li>					
					</ul>
					<ul>
					<li class='lable'>소속 부문</li>
						<li class='value'>
						<select name='bumun[]' style="width:155px; margin-left:2px">
						<option value="">:: 부문 선택</option>
						<?
						$qry = "SELECT * FROM uatp_bumun";
						$query = DBquery($qry);
						while($bumun = mysql_fetch_array($query)){
							?>
						<option value="<?=$bumun['no']?>"<?if($bumun['no']==$list['bumun_no']){echo "selected";}?>><?=$bumun['name']?></option>
						<?
						}
						mysql_close();
						?>
						</select>
						</li>					
					</ul>
					<ul>
					<li class='lable'>소속 분류</li>
						<li class='value' style="width:160px">
						<select name="bigcategory[]" style="width:155px; margin-left:2px">
						<option value="-1">:: 대분류 선택 ::</option>
						<?
						$qry = "SELECT * FROM uatp_biggestcategory";
						$query = DBquery($qry);
						while($big = mysql_fetch_array($query)){
						?>
						<option value="<?=$big['no']?>"<?if($big['no']==$list['b_no']){echo "selected";}?>><?=$big['name']?></option>
						<?
						}
						mysql_close();
						?>
						</select>
						</li>
						<li class='value' style="width:160px">
						<select name="middlecategory[]" style="width:155px; margin-left:2px">
						<option value="">:: 중분류 선택 ::</option>
						<?
						$qry = "SELECT * FROM uatp_middlecategory WHERE b_no = $list[b_no]";
						$query = DBquery($qry);
						while($middle = mysql_fetch_array($query)){
						?>
						<option value="<?=$middle['no']?>"<?if($middle['no']==$list['m_no']){echo "selected";}?>><?=$middle['name']?></option>
						<?
						}
						mysql_close();
						?>
						</select>
						</li>
						<li class='value' style="width:160px">
						<select name="smallcategory[]" style="width:155px; margin-left:2px">
						<option value="">:: 소분류 선택 ::</option>
						<?
						$qry = "SELECT * FROM uatp_smallcategory WHERE m_no = $list[m_no]";
						$query = DBquery($qry);
						while($small = mysql_fetch_array($query)){
						?>
						<option value="<?=$small['no']?>"<?if($small['no']==$list['s_no']){echo "selected";}?>><?=$small['name']?></option>
						<?
						}
						mysql_close();
						?>
						</select>
						</li>											
					</ul>
					<ul>
					<li class='lable'>단위</li>
						<li class='value'>
						<select name='unit[]' style="width:155px; margin-left:2px">
						<option value=''>:: 단위 선택</option>
						<option value='EA'  <?if($list['unit']=='EA')  echo "selected";?>>EA</option>
						<option value='BOX' <?if($list['unit']=='BOX') echo "selected";?>>BOX</option>
						<option value='g'   <?if($list['unit']=='g')   echo "selected";?>>g</option>
						<option value='kg'  <?if($list['unit']=='kg')  echo "selected";?>>kg</option>
						<option value='ℓ'   <?if($list['unit']=='ℓ')   echo "selected";?>>ℓ</option>
						<option value='㎖'  <?if($list['unit']=='㎖')  echo "selected";?>>㎖</option>
						<option value='ro'  <?if($list['unit']=='ro')  echo "selected";?>>ro</option>
						</select>
						</li>
					</ul>
					<ul>
					<li class='lable'>Rot</li>
						<li class='detail'><input type='checkbox' name='rot[]'  value="1" onclick="javascript:show_rot(<?=$i?>);"  <?if($list['rot']=='1')  echo "checked";?>></input>
						</li>				
					</ul>
					<ul name='show_ul[]' id='show_ul[]' style="display:none; margin-left:50px; border-left:1px solid #eaeaea; background:#f9f9f9;">
					<li class='lable'>Rot 수</li>
						<li class='value' style="width:100px;">
						<input type='text' size='5' name='rotcnt[]' value="<?=$list['rotcnt']?>" onkeyup="number_check(this);" style="text-align:right;"/>
						</li>	
						<li class='lable'>Rot Barcode</li>
						<li class='value'>
						<input type='text' size='20' name='rot_barcode[]' value="<?=$list['rot_barcode']?>" readonly onclick="javascript:chk_rot_barcode('<?=$table?>',this.value,<?=$i?>);"/>
						</li>			
					</ul>
					<ul>
					<li class='lable'>재고관리</li>
						<li class='detail'><input type='checkbox' name='stock[]' value="1" <?if($list['stock']=='1'){echo "checked";}?>></input>
						</li>				
					</ul>
					<ul>
					<li class='lable'>마이너스 키</li>
						<li class='detail'><input type='checkbox' name='minus[]' value="1" <?if($list['minus']=='1'){echo "checked";}?>></input>
						</li>				
					</ul>
					<ul>
					<li class='lable'>비고1</li>
						<li class='value' style='width:700px'><input type='text' size='80' name='note1[]' value="<?=$list['note1']?>"/></li>				
					</ul>
					<ul>
					<li class='lable'>비고2</li>
						<li class='value' style='width:700px'><input type='text' size='80' name='note2[]' value="<?=$list['note2']?>"/></li>				
					</ul>
					<ul>
					<li class='lable'>비고3</li>
						<li class='value' style='width:700px'><input type='text' size='80' name='note3[]' value="<?=$list['note3']?>"/></li>				
					</ul>
					<ul style='height:185px;'>
					<li class='lable'>Image</li>
						<li class='value' style='width:600px'><input name="productimagedir[]" onKeyPress="return false" value="" type="file" size="64"/></li>			
						<li class='lable' style='border:1px solid #c5c5c5;height:170px;'>
					<?php
					if($list['productimagedir']){ 
					echo "<img src='up_file/$list[productimagedir]' style='width:150px; height:170px;'/>";
					}
					?>
					</li>
					</ul>
					
					<ul class='line'></ul>
					<ul class='line'></ul>
				<!--   /////////////////////	  기존 내용 수정하기	 ///////////////////// -->
				
				
			
			<?php }
				 }else{
			?>
			
				<!--   /////////////////////  새로운 내용 입력하는 부분    ///////////////////// -->
			<input type="hidden" value="" name="no[]"/>
			<ul class='line'></ul>
					<ul>
					<li class='lable'>barcode</li>
						<li class='value'><input type='text' size='20' name='barcode[]' value="" readonly onclick="javascript:chk_barcode('<?=$table?>',this.value);"/>
						</li>
						<li class='explain'>:: 중복 불가능 하며 숫자만 입력 가능합니다.</li>						
					</ul>
					<ul>
					<li class='lable'>상품명</li>
						<li class='value'><input type='text' size='20' name='name[]' value="" readonly onclick="javascript:chk_productname('<?=$table?>',this.value);"/>
						</li>
						<li class='explain'>:: 상품명은 중복될 수 없습니다.</li>						
					</ul>
					<ul>
					<li class='lable'>상품명(가나)</li>
						<li class='value'><input type='text' size='20' name='productnamegana[]' value=""/>
						</li>					
					</ul>
					<ul>
					<li class='lable'>가격 1</li>
						<li class='value' style="width:170px">
						<input type='text' size='20' name='price1[]' value="" onkeyup="number_check(this);" style="text-align:right"/>
						</li>
						<li class='value' style="width:190px">&nbsp;2.
						<input type='text' size='20' name='price2[]' value="" onkeyup="number_check(this);" style="text-align:right"/>
						</li>
						<li class='value' style="width:190px">&nbsp;3.
						<input type='text' size='20' name='price3[]' value="" onkeyup="number_check(this);" style="text-align:right"/>
						</li>											
					</ul>
					<ul>
					<li class='lable'>구매처</li>
						<li class='value'>
						<select name='buyer[]' style="width:155px; margin-left:2px">
						<option value="">:: 구매처 선택</option>
						<?
						$qry = "SELECT * FROM uatp_buyer";
						$query = DBquery($qry);
						while($list = mysql_fetch_array($query)){
							?>
						<option value="<?=$list['no']?>"><?=$list['name']?></option>
						<?
						}
						mysql_close();
						?>
						</select>
						</li>					
					</ul>
					<ul>
					<li class='lable'>구매가격</li>
						<li class='value'>
						<input type='text' size='20' name='buyingprice[]' value="" onkeyup="number_check(this);" style="text-align:right"/>
						</li>					
					</ul>
					<ul>
					<li class='lable'>소속 부문</li>
						<li class='value'>
						<select name='bumun[]' style="width:155px; margin-left:2px">
						<option value="">:: 부문 선택</option>
						<?
						$qry = "SELECT * FROM uatp_bumun";
						$query = DBquery($qry);
						while($list = mysql_fetch_array($query)){
							?>
						<option value="<?=$list['no']?>"><?=$list['name']?></option>
						<?
						}
						mysql_close();
						?>
						</select>
						</li>					
					</ul>
					<ul>
					<li class='lable'>소속 분류</li>
						<li class='value' style="width:160px">
						<select name="bigcategory[]" style="width:155px; margin-left:2px">
						<option value="-1">:: 대분류 선택 ::</option>
						<?
						$qry = "SELECT * FROM uatp_biggestcategory";
						$query = DBquery($qry);
						while($list = mysql_fetch_array($query)){
						?>
						<option value="<?=$list['no']?>"><?=$list['name']?></option>
						<?
						}
						mysql_close();
						?>
						</select>
						</li>
						<li class='value' style="width:160px">
						<select name="middlecategory[]" style="width:155px; margin-left:2px">
						<option value="">:: 중분류 선택 ::</option>
						</select>
						</li>
						<li class='value' style="width:160px">
						<select name="smallcategory[]" style="width:155px; margin-left:2px">
						<option value="">:: 소분류 선택 ::</option>
						</select>
						</li>											
					</ul>
					<ul>
					<li class='lable'>단위</li>
						<li class='value'>
						<select name='unit[]' style="width:155px; margin-left:2px">
						<option value=''>:: 단위 선택</option>
						<option value='EA'>EA</option>
						<option value='BOX'>BOX</option>
						<option value='g'>g</option>
						<option value='kg'>kg</option>
						<option value='ℓ'>ℓ</option>
						<option value='㎖'>㎖</option>
						<option value='ro'>ro</option>
						</select>
						</li>					
					</ul>
					<ul>
					<li class='lable'>Rot</li>
						<li class='detail'><input type='checkbox' name='rot[]'  value="1" onclick="javascript:show_rot(0);"></input>
						</li>				
					</ul>
					<ul name='show_ul[]' id='show_ul[]' style="display:none;margin-left:50px;border-left:1px solid #eaeaea;background:#f9f9f9;">
					<li class='lable'>Rot 수</li>
						<li class='value' style="width:100px;">
						<input type='text' size='5' name='rotcnt[]' value="" onkeyup="number_check(this);" style="text-align:right;"/>
						</li>	
						<li class='lable'>Rot Barcode</li>
						<li class='value'>
						<input type='text' size='20' name='rot_barcode[]' value="" readonly onclick="javascript:chk_rot_barcode('<?=$table?>',this.value,0);"/>
						</li>			
					</ul>
					<ul>
					<li class='lable'>재고관리</li>
						<li class='detail'><input type='checkbox' name='stock[]' value="1"></input>
						</li>				
					</ul>
					<ul>
					<li class='lable'>마이너스 키</li>
						<li class='detail'><input type='checkbox' name='minus[]' value="1"></input>
						</li>				
					</ul>
					<ul>
					<li class='lable'>비고1</li>
						<li class='value' style='width:700px'><input type='text' size='80' name='note1[]' value=""/></li>				
					</ul>
					<ul>
					<li class='lable'>비고2</li>
						<li class='value' style='width:700px'><input type='text' size='80' name='note2[]' value=""/></li>				
					</ul>
					<ul>
					<li class='lable'>비고3</li>
						<li class='value' style='width:700px'><input type='text' size='80' name='note3[]' value=""/></li>				
					</ul>
					<ul>
					<li class='lable'>Image</li>
						<li class='value' style='width:700px'><input name="productimagedir[]" onKeyPress="return false" type="file" size="64"/></li>				
					</ul>
			<!--   /////////////////////  새로운 내용 입력하는 부분    ///////////////////// -->
			
		<?php }
		?>
		<ul class='line'></ul>
	</div>
			<div style="padding: 5px;">
				<center>
					<input type="submit" class="button white small" value="입력하기" /> <input
						type="button" class="button white small" value="취소하기"
						onclick="javacsript:location.href='view.php'" />
				</center>
			</div>
		</form>
	</div>
</body>
</html>